package cn.hxh.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author: HongXiaoHan
 * @Description
 * @Date: 2020/8/21 12:15
 */
public class CharSetFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        System.out.println(req.getRequestURI());
        if (req.getRequestURI().endsWith("/a/filterServlet1")){
            System.out.println("没有过滤");
        }else {
            System.out.println("w");
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=UTF-8");
        }
        chain.doFilter(req,response);
    }
}
